package com.shrct.businessprocess.customerservice.impl;

import com.shrct.businessprocess.customerservice.RCRoutineServiceWorkItem;
import com.shrct.businessprocess.customerservice.RCRoutineServiceWorkItemCriteria;
import com.shrct.businessprocess.customerservice.RCWorkItemStatus;
import edu.fudan.mylang.pf.query.HQLBasedPagedQueryCriteria;
import java.util.Date;
import org.hibernate.Query;

public class RCRoutineServiceWorkItemCriteriaImpl extends HQLBasedPagedQueryCriteria<RCRoutineServiceWorkItem> implements RCRoutineServiceWorkItemCriteria {
  private RCWorkItemStatus status;
  
  public RCWorkItemStatus getStatus() {
    return this.status;
  }
  
  public RCRoutineServiceWorkItemCriteria setStatus(final RCWorkItemStatus status) {
    this.status = status;
    return this;			
    
  }
  
  private Date planDateFrom;
  
  public Date getPlanDateFrom() {
    return this.planDateFrom;
  }
  
  public RCRoutineServiceWorkItemCriteria setPlanDateFrom(final Date planDateFrom) {
    this.planDateFrom = planDateFrom;
    return this;			
    
  }
  
  private Date planDateTo;
  
  public Date getPlanDateTo() {
    return this.planDateTo;
  }
  
  public RCRoutineServiceWorkItemCriteria setPlanDateTo(final Date planDateTo) {
    this.planDateTo = planDateTo;
    return this;			
    
  }
  
  protected String buildHQLFrom() {
    return " from com.shrct.businessprocess.customerservice.impl.RCRoutineServiceWorkItemImpl this ";
  }
  
  protected String buildHQLBody() {
    String hql = "where 1 = 1 ";
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getStatus()) ){
    	hql += " and ((this.status) = (:status))" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getPlanDateFrom()) ){
    	hql += " and ((this.planDate) >= (:planDateFrom))" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getPlanDateTo()) ){
    	hql += " and ((this.planDate) <= (:planDateTo))" ;
    }
    return hql;
    
  }
  
  public void initOrderBys() {
    addOrder("this.planDate",edu.fudan.mylang.pf.query.OrderItem.DESC);
  }
  
  protected void fillParameter(final Query query) {
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getStatus())){
    	query.setParameter("status",getStatus()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getPlanDateFrom())){
    	query.setParameter("planDateFrom",getPlanDateFrom()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getPlanDateTo())){
    	query.setParameter("planDateTo",getPlanDateTo()) ;
    }			
    
  }
  
  protected Boolean isDistinct() {
    return false;
  }
  
  public RCRoutineServiceWorkItemCriteriaImpl() {
    initOrderBys();
  }
}
